home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / usenet / volume4 / nobs < prev    next >
Encoding:
Internet Message Format  |  1988-03-24  |  35.4 KB

  1. Path: uunet!tektronix!tekgen!tekred!games
  2. From: games@tekred.TEK.COM
  3. Newsgroups: comp.sources.games
  4. Subject: v04i002:  nobs - cribbage game
  5. Keywords: cribbage
  6. Message-ID: <2329@tekred.TEK.COM>
  7. Date: 24 Mar 88 20:19:17 GMT
  8. Sender: billr@tekred.TEK.COM
  9. Lines: 1548
  10. Approved: billr@saab.CNA.TEK.COM
  11.  
  12. Submitted by: "g.l.sicherman" <gls@odyssey.att.com>
  13. Comp.sources.games: Volume 4, Issue 2
  14. Archive-name: nobs
  15.  
  16.     [This is the first of two cribbage games to be posted. This
  17.      game should run under System V or BSD (I tested it under
  18.      Sun 3.5).   -br]
  19.  
  20. #! /bin/sh
  21. # This is a shell archive.  Remove anything before this line, then unpack
  22. # it by saving it into a file and typing "sh file".  To overwrite existing
  23. # files, type "sh file -c".  You can also feed this as standard input via
  24. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  25. # will see the following message at the end:
  26. #        "End of archive 1 (of 1)."
  27. # Contents:  README MANIFEST Makefile deal.c defs.h gamescore.c globs.c
  28. #   globs.h human.c logaux.c logglobs.c logglobs.h nobs.6 nobs.c
  29. #   pegs.c play.c playscore.c progaux.c program.c show.c shuf.c
  30. #   version.c wglobs.c window.c window.h
  31. # Wrapped by billr@saab on Thu Mar 24 12:14:14 1988
  32. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  33. if test -f README -a "${1}" != "-c" ; then 
  34.   echo shar: Will not over-write existing file \"README\"
  35. else
  36. echo shar: Extracting \"README\" \(243 characters\)
  37. sed "s/^X//" >README <<'END_OF_README'
  38. XThis is the first C distribution of the Colonel's Cribbage
  39. XProgram.  (It originally ran in FORTRAN IV on a CDC, back in the
  40. X70's.)  All configurables are in the Makefile.
  41. XFeedback to ihnp4!odyssey!gls.  Have fun!
  42. X
  43. XRed Hill Road
  44. XMarch 11, 1988
  45. END_OF_README
  46. if test 243 -ne `wc -c <README`; then
  47.     echo shar: \"README\" unpacked with wrong size!
  48. fi
  49. # end of overwriting check
  50. fi
  51. if test -f MANIFEST -a "${1}" != "-c" ; then 
  52.   echo shar: Will not over-write existing file \"MANIFEST\"
  53. else
  54. echo shar: Extracting \"MANIFEST\" \(864 characters\)
  55. sed "s/^X//" >MANIFEST <<'END_OF_MANIFEST'
  56. X   File Name        Archive #    Description
  57. X-----------------------------------------------------------
  58. X MANIFEST                  1    This shipping list
  59. X Makefile                  1    
  60. X README                    1    
  61. X deal.c                    1    
  62. X defs.h                    1    
  63. X gamescore.c               1    
  64. X globs.c                   1    
  65. X globs.h                   1    
  66. X human.c                   1    
  67. X logaux.c                  1    
  68. X logglobs.c                1    
  69. X logglobs.h                1    
  70. X nobs.6                    1    
  71. X nobs.c                    1    
  72. X pegs.c                    1    
  73. X play.c                    1    
  74. X playscore.c               1    
  75. X progaux.c                 1    
  76. X program.c                 1    
  77. X show.c                    1    
  78. X shuf.c                    1    
  79. X version.c                 1    
  80. X wglobs.c                  1    
  81. X window.c                  1    
  82. X window.h                  1    
  83. END_OF_MANIFEST
  84. if test 864 -ne `wc -c <MANIFEST`; then
  85.     echo shar: \"MANIFEST\" unpacked with wrong size!
  86. fi
  87. # end of overwriting check
  88. fi
  89. if test -f Makefile -a "${1}" != "-c" ; then 
  90.   echo shar: Will not over-write existing file \"Makefile\"
  91. else
  92. echo shar: Extracting \"Makefile\" \(1133 characters\)
  93. sed "s/^X//" >Makefile <<'END_OF_Makefile'
  94. X#    Makefile for nobs.
  95. X#    G. L. Sicherman (ihnp4!odyssey!gls).  March 1988.
  96. X#-------
  97. X# Configurable parameters:
  98. XBINDEST=$$HOME/bin/nobs
  99. XMANDEST=$$HOME/man/nobs.6
  100. X
  101. X# Define BSD for Berkeley, Sun, etc.
  102. X# BSDFLAG= -DBSD
  103. XBSDFLAG= -UBSD
  104. X
  105. X# If BSD, we need libtermcap.
  106. X# LIB= -lcurses -ltermcap
  107. XLIB= -lcurses
  108. X
  109. X# End of configurable parameters.  Good luck!
  110. X
  111. XCFLAGS= -O $(BSDFLAG)
  112. X
  113. XOBJS = nobs.o logglobs.o window.o gamescore.o deal.o shuf.o play.o human.o \
  114. X   pegs.o program.o playscore.o show.o progaux.o logaux.o wglobs.o globs.o \
  115. X   version.o
  116. X
  117. XSHARS = nobs.c logglobs.c window.c gamescore.c deal.c shuf.c play.c human.c \
  118. X   pegs.c program.c playscore.c show.c progaux.c logaux.c wglobs.c \
  119. X   globs.c version.c defs.h globs.h logglobs.h window.h nobs.6 Makefile README
  120. X
  121. Xall: nobs
  122. Xnobs: $(OBJS)
  123. X    cc -o nobs $(OBJS) $(LIB)
  124. X$(OBJS): defs.h globs.h
  125. Xlog.o progaux.o program.o: logglobs.h
  126. Xplay.o program.o human.o gamescore.o pegs.o window.o show.o: window.h
  127. X
  128. Xinstall: nobs nobs.6
  129. X    rm -f $(BINDEST) $(MANDEST)
  130. X    cp nobs $(BINDEST)
  131. X    cp nobs.6 $(MANDEST)
  132. X
  133. Xshar: nobs.shar
  134. Xnobs.shar: $(SHARS)
  135. X    shar $(SHARS) > $@
  136. X
  137. Xclean:
  138. X    rm -f nobs *.o nobs.shar
  139. END_OF_Makefile
  140. if test 1133 -ne `wc -c <Makefile`; then
  141.     echo shar: \"Makefile\" unpacked with wrong size!
  142. fi
  143. # end of overwriting check
  144. fi
  145. if test -f deal.c -a "${1}" != "-c" ; then 
  146.   echo shar: Will not over-write existing file \"deal.c\"
  147. else
  148. echo shar: Extracting \"deal.c\" \(218 characters\)
  149. sed "s/^X//" >deal.c <<'END_OF_deal.c'
  150. X#include "defs.h"
  151. X#include "globs.h"
  152. X
  153. Xdeal()
  154. X{
  155. X    int i;
  156. X    CARD *packp;
  157. X    shuf();
  158. X    packp = pack+39;    /* Only the last 13 cards */
  159. X    for (i=0; i<6; i++) {
  160. X        hand[0][i] = *packp++;
  161. X        hand[1][i] = *packp++;
  162. X    }
  163. X    cut = *packp;
  164. X}
  165. END_OF_deal.c
  166. if test 218 -ne `wc -c <deal.c`; then
  167.     echo shar: \"deal.c\" unpacked with wrong size!
  168. fi
  169. # end of overwriting check
  170. fi
  171. if test -f defs.h -a "${1}" != "-c" ; then 
  172.   echo shar: Will not over-write existing file \"defs.h\"
  173. else
  174. echo shar: Extracting \"defs.h\" \(688 characters\)
  175. sed "s/^X//" >defs.h <<'END_OF_defs.h'
  176. X/*
  177. X *    defs.h - definitions.
  178. X */
  179. X
  180. X/*    Suit has 3 bits, so we can use the green suit for estimating the cut.
  181. X */
  182. X#define RANK(x) ((x)&0017)
  183. X#define    SUIT(x) (((x)&0160)>>4)
  184. X#define    SAMESUIT(x,y) (!((x^y)&0160))
  185. X#define    MAKECARD(r,s) ((r)|((s)<<4))
  186. X
  187. Xtypedef    char    PLAYER;
  188. X
  189. X#define    PROGRAM    0
  190. X#define    HUMAN    1
  191. X
  192. X#define    SCOREUP(a,b) {if (scoreup((a),(b))) {gameover++; return;}}
  193. X#define    CABBAGE    4
  194. X#define    SPADE    3
  195. X#define    HEART    2
  196. X#define    DIAMOND    1
  197. X#define    CLUB    0
  198. X
  199. X#define    KING    13
  200. X#define    QUEEN    12
  201. X#define    KNAVE    11
  202. X#define    TEN    10
  203. X#define    NINE    9
  204. X#define    EIGHT    8
  205. X#define    SEVEN    7
  206. X#define    SIX    6
  207. X#define    FIVE    5
  208. X#define    FOUR    4
  209. X#define    TREY    3
  210. X#define    DEUCE    2
  211. X#define    ACE    1
  212. X
  213. Xtypedef    char    CARD;
  214. X
  215. Xvoid    shuf();
  216. END_OF_defs.h
  217. if test 688 -ne `wc -c <defs.h`; then
  218.     echo shar: \"defs.h\" unpacked with wrong size!
  219. fi
  220. # end of overwriting check
  221. fi
  222. if test -f gamescore.c -a "${1}" != "-c" ; then 
  223.   echo shar: Will not over-write existing file \"gamescore.c\"
  224. else
  225. echo shar: Extracting \"gamescore.c\" \(3455 characters\)
  226. sed "s/^X//" >gamescore.c <<'END_OF_gamescore.c'
  227. X#include "defs.h"
  228. X#include "globs.h"
  229. X#include "window.h"
  230. X
  231. Xgamescore()
  232. X{
  233. X    sleep(2);
  234. X    handscore(!dealer);
  235. X    if (!gameover) {
  236. X        sleep(2);
  237. X        handscore(dealer);
  238. X    }
  239. X    if (!gameover) {
  240. X        sleep(1);
  241. X        werase(Pscore);
  242. X        werase(Hscore);
  243. X        exposecrib();
  244. X        sleep(2);
  245. X        cribscore();
  246. X    }
  247. X}
  248. X
  249. Xhandscore(who)
  250. Xint who;
  251. X{
  252. X    int i;
  253. X    CARD dummy[5];
  254. X    for (i=0; i<4; i++) dummy[i]=hand[who][i];
  255. X    dummy[4]=cut;
  256. X    evalhand(dummy, 0, who);
  257. X}
  258. X
  259. Xcribscore()
  260. X{
  261. X    int i;
  262. X    CARD dummy[5];
  263. X    for (i=0; i<4; i++) dummy[i]=crib[i];
  264. X    dummy[4]=cut;
  265. X    evalhand(dummy, 1, dealer);
  266. X}
  267. X
  268. Xint
  269. Xevalhand(ehand, iscrib, whoscore)
  270. XCARD ehand[];
  271. Xint iscrib;
  272. Xint whoscore;    /* -1 means silent */
  273. X{
  274. X/*
  275. X *    If iscrib is on, don't allow four-flushes.
  276. X */
  277. X    int i, j, mask, bit, hmask, sum, hcount;
  278. X    char *runname;
  279. X    int runval;
  280. X    short rep[15];        /* Extra zeroes make it easier */
  281. X    WINDOW *Win;
  282. X    if (whoscore==1) Win=Hscore;
  283. X    else if (whoscore==0) Win=Pscore;
  284. X    if (iscrib && whoscore>=0) {
  285. X        wprintw(Win, "%s Crib:\n", whoscore? "Your": "My");
  286. X        wrefresh(Win);
  287. X        sleep(1);
  288. X    }
  289. X    hcount=0;
  290. X    for (mask=1; mask<32; mask++) {
  291. X        hmask=mask;
  292. X        sum=0;
  293. X        for (bit=0; bit<5; bit++) {
  294. X            if (1&hmask)
  295. X                sum+=rankvalue[RANK(ehand[bit])];
  296. X            hmask >>= 1;
  297. X        }
  298. X        if (sum==15) {
  299. X            hcount += 2;
  300. X            if (whoscore>=0) {
  301. X                wprintw(Win, "Fifteen-%d\n", hcount);
  302. X                wrefresh(Win);
  303. X                sleep(1);
  304. X            }
  305. X        }
  306. X/*
  307. X *    Need we add any cards?
  308. X */
  309. X        if (sum >= 15) mask |= mask-1;
  310. X    }
  311. X/*
  312. X *    Count the ranks.
  313. X */
  314. X    for (i=1; i<15; i++) rep[i]=0;
  315. X    for (i=0; i<5; i++) rep[RANK(ehand[i])]+=1;
  316. X/*
  317. X *    Look for isolated pairs, etc.
  318. X */
  319. X    for (i=1; i<14; i++) if (rep[i]>1) {
  320. X        if (!(rep[i-1] && (rep[i-2] || rep[i+1]) ||
  321. X        rep[i+1] && rep[i+2])) {
  322. X            hcount += pairvalue[rep[i]];
  323. X            if (whoscore>=0) {
  324. X                wprintw(Win, "and a %s is %d\n", 
  325. X                pairname[rep[i]], hcount);
  326. X                wrefresh(Win);
  327. X                sleep(1);
  328. X            }
  329. X        }
  330. X    }
  331. X/*
  332. X *    Look for runs, including multiples.
  333. X */
  334. X    for (i=1; i<12; i++) if (rep[i]) {
  335. X        if (!rep[i+2]) {
  336. X            i+=2;
  337. X            continue;
  338. X        }
  339. X        if (!rep[i+1]) {
  340. X            i+=1;
  341. X            continue;
  342. X        }
  343. X/*
  344. X *    We have a run!
  345. X */
  346. X        if (rep[i+3]) {
  347. X            if (rep[i+4]) {
  348. X                runname="Sequence of Five\n";
  349. X                runval=5;
  350. X            }
  351. X            else {
  352. X                runname="Sequence of Four\n";
  353. X                runval=4;
  354. X                for (j=i; j<i+4; j++) if (rep[j]>1) {
  355. X                    runname="Double Sequence\n of Four";
  356. X                    runval=10;
  357. X                    break;
  358. X                }
  359. X            }
  360. X        }
  361. X        else {
  362. X            for (sum=0, j=i; j<i+3; j++) {
  363. X                if (rep[j]==3) {
  364. X                    runname="Triple Sequence";
  365. X                    runval=15;
  366. X                    goto scorerun;
  367. X                }
  368. X                sum += rep[j]-1;
  369. X            }
  370. X            runname=drunname[sum];
  371. X            runval=drunval[sum];
  372. X        }
  373. Xscorerun:
  374. X        hcount += runval;
  375. X        if (whoscore>=0) {
  376. X            wprintw(Win, "and a %s is %d\n", runname, hcount);
  377. X            wrefresh(Win);
  378. X            sleep(1);
  379. X        }
  380. X        break;        /* You can't have two runs */
  381. X    }
  382. X/*
  383. X *    Check for flushes.
  384. X */
  385. X    for (i=1; i<4; i++) if (!SAMESUIT(ehand[i],ehand[0])) goto endflush;
  386. X    if (SAMESUIT(ehand[4], ehand[0])) {
  387. X        hcount += 5;
  388. X        if (whoscore>=0) {
  389. X            wprintw(Win, "and a Flush of Five is %d\n", hcount);
  390. X            wrefresh(Win);
  391. X            sleep(1);
  392. X        }
  393. X    }
  394. X    else if (!iscrib) {
  395. X        hcount += 4;
  396. X        if (whoscore>=0) {
  397. X            wprintw(Win, "and a Flush is %d\n", hcount);
  398. X            wrefresh(Win);
  399. X            sleep(1);
  400. X        }
  401. X    }
  402. Xendflush:
  403. X    for (i=0; i<4; i++)
  404. X    if (RANK(ehand[i])==KNAVE && SAMESUIT(ehand[i], ehand[4])) {
  405. X        hcount += 1;
  406. X        if (whoscore>=0) {
  407. X            wprintw(Win, "and One for His Nobs is %d\n",hcount);
  408. X            wrefresh(Win);
  409. X            sleep(1);
  410. X        }
  411. X        break;
  412. X    }
  413. X/*
  414. X *    Final reckoning, if wanted.
  415. X */
  416. X    if (whoscore>=0) {
  417. X        sleep(1);
  418. X        if (hcount) SCOREUP(whoscore, hcount);
  419. X    }
  420. X    return hcount;
  421. X}
  422. END_OF_gamescore.c
  423. if test 3455 -ne `wc -c <gamescore.c`; then
  424.     echo shar: \"gamescore.c\" unpacked with wrong size!
  425. fi
  426. # end of overwriting check
  427. fi
  428. if test -f globs.c -a "${1}" != "-c" ; then 
  429.   echo shar: Will not over-write existing file \"globs.c\"
  430. else
  431. echo shar: Extracting \"globs.c\" \(997 characters\)
  432. sed "s/^X//" >globs.c <<'END_OF_globs.c'
  433. X/*
  434. X *    globs - global variables.
  435. X */
  436. X
  437. X#include "defs.h"
  438. X
  439. Xshort    count;
  440. XCARD    crib[6];
  441. XCARD    cut;
  442. Xint    dealer;
  443. Xint    (*dscfunc[2])();
  444. Xchar    gameover;
  445. XCARD    go[8];
  446. Xshort    gocount;
  447. XCARD    hand[2][6];
  448. Xchar    handover;
  449. Xshort    ncrib;
  450. Xshort    nleft[2];
  451. XCARD    pack[52];
  452. Xint    packmade = 0;
  453. Xshort    peg[2][2];
  454. Xchar    played[2][4];
  455. XPLAYER    playertype[2];
  456. Xchar    quitflag;
  457. Xshort    score[2];
  458. Xshort    whosego;
  459. Xchar    whoseturn;
  460. X
  461. Xchar    *drunname[3] = {"Sequence","Double Sequence",
  462. X        "Quadruple Sequence"};
  463. Xshort    drunval[3] = {3, 8, 16};
  464. Xchar    *pairname[5] = {"0","0","Pair","Pair Royal","Double Pair Royal"};
  465. Xshort    pairvalue[5] = {0,0,2,6,12};
  466. Xchar    *rankname[14] = {"0", "Ace","Deuce","Trey","Four",
  467. X            "Five","Six","Seven","Eight","Nine","Ten",
  468. X            "Knave","Queen","King"};
  469. Xchar    *rankrdr[14] = {"0", "A",
  470. X        "2","3","4","5","6","7","8","9","10","J","Q","K"};
  471. Xshort    rankvalue[14] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10};
  472. Xchar    *suitname[5] = {"Clubs", "Diamonds", "Hearts", "Spades", "Cabbages"};
  473. Xchar    *suitrdr[5] = {"c","d","h","s","x"};
  474. END_OF_globs.c
  475. if test 997 -ne `wc -c <globs.c`; then
  476.     echo shar: \"globs.c\" unpacked with wrong size!
  477. fi
  478. # end of overwriting check
  479. fi
  480. if test -f globs.h -a "${1}" != "-c" ; then 
  481.   echo shar: Will not over-write existing file \"globs.h\"
  482. else
  483. echo shar: Extracting \"globs.h\" \(762 characters\)
  484. sed "s/^X//" >globs.h <<'END_OF_globs.h'
  485. X/*
  486. X *    globs.h - global variables.
  487. X */
  488. X
  489. Xextern    short    count;
  490. Xextern    CARD    crib[6];
  491. Xextern    CARD    cut;
  492. Xextern    int    dealer;
  493. Xextern    char    *drunname[];
  494. Xextern    short    drunval[];
  495. Xextern    int    (*dscfunc[])();
  496. Xextern    char    gameover;
  497. Xextern    CARD    go[8];
  498. Xextern    short    gocount;
  499. Xextern    CARD    hand[2][6];
  500. Xextern    char    handover;
  501. Xextern    short    ncrib;
  502. Xextern    short    nleft[2];
  503. Xextern    CARD    pack[52];
  504. Xextern    int    packmade;
  505. Xextern    char    *pairname[];
  506. Xextern    short    pairvalue[];
  507. Xextern    short    peg[2][2];
  508. Xextern    char    played[2][4];
  509. Xextern    PLAYER    playertype[2];
  510. Xextern    char    quitflag;
  511. Xextern    char    *rankname[14];
  512. Xextern    char    *rankrdr[14];
  513. Xextern    short    rankvalue[14];
  514. Xextern    short    score[2];
  515. Xextern    char    *suitname[5];
  516. Xextern    char    *suitrdr[5];
  517. Xextern    char    version[];
  518. Xextern    short    whosego;
  519. Xextern    char    whoseturn;
  520. END_OF_globs.h
  521. if test 762 -ne `wc -c <globs.h`; then
  522.     echo shar: \"globs.h\" unpacked with wrong size!
  523. fi
  524. # end of overwriting check
  525. fi
  526. if test -f human.c -a "${1}" != "-c" ; then 
  527.   echo shar: Will not over-write existing file \"human.c\"
  528. else
  529. echo shar: Extracting \"human.c\" \(2424 characters\)
  530. sed "s/^X//" >human.c <<'END_OF_human.c'
  531. X#include "defs.h"
  532. X#include "globs.h"
  533. X#include "window.h"
  534. X#ifdef BSD
  535. X#include <ctype.h>
  536. X#define beep()    putchar('\007')
  537. X#endif
  538. X
  539. Xhumandiscard(hand, mydeal)
  540. XCARD hand[];
  541. Xint mydeal;
  542. X{
  543. X    char selected[6];
  544. X    int nselected;
  545. X    int j, j1, j2;
  546. X    char k;
  547. X    for (j=0; j<6; j++) mvwaddch(Select, 0, 5*j+2, 'a'+j);
  548. X    wrefresh(Select);
  549. X    mvwprintw(
  550. X    Prompt, 0, 0, mydeal? "It is your crib.\n": "It is my crib.\n");
  551. X    mvwprintw(Prompt, 1, 0, "Select 2 cards.  Type RETURN to discard.\n");
  552. X    for (j=0; j<6; j++) selected[j]=0;
  553. X    nselected = 0;
  554. X    for (;;) {
  555. X        mvwaddch(Prompt, 1, 41, '\n');
  556. X        wmove(Prompt, 1, 41);
  557. X        wrefresh(Prompt);
  558. X        k = wgetch(Prompt);
  559. X        k = (isupper(k) ? tolower(k) : k);
  560. X        if ('\n'==k) {
  561. X            if (nselected == 2) break;
  562. X            beep();
  563. X            continue;
  564. X        }
  565. X        if (k > 'f' || k < 'a') {
  566. X            beep();
  567. X            continue;
  568. X        }
  569. X        nselected -= selected[k-'a'];
  570. X        nselected += (selected[k-'a'] ^= 1);
  571. X        mvwaddch(Humanhand, 2, 5*(k-'a')+3,
  572. X            selected[k-'a']? '*': ' ');
  573. X        wrefresh(Humanhand);
  574. X    }
  575. X    wclear(Select);
  576. X    wclear(Prompt);
  577. X    wrefresh(Select);
  578. X    wrefresh(Prompt);
  579. X    for (j=0; j<6; j++) if (selected[j]) {
  580. X        j1 = j2;    /* and you know Lint won't like this! */
  581. X        j2 = j;
  582. X    }
  583. X    makediscard(hand, j1, j2);
  584. X}
  585. X
  586. Xhumanplay()
  587. X{
  588. X    char k;
  589. X    int sco;
  590. X    if (whosego == whoseturn) {
  591. X/*
  592. X *    It is my go.  Can I play?
  593. X */
  594. X        if (goodgo(whoseturn)) {
  595. X            SCOREUP(whoseturn, 1);
  596. X            resetgo();
  597. X            handover = !nleft[0] && !nleft[1];
  598. X            return;
  599. X        }
  600. X        else mvwprintw(Prompt, 1, 0, "Select a card.\n");
  601. X    }
  602. X    else if (!nleft[whoseturn]) {
  603. X        handover = !nleft[0] && !nleft[1];
  604. X        if (handover) SCOREUP(whoseturn, 1);
  605. X        return;
  606. X    }
  607. X    else if (whosego == !whoseturn) return;
  608. X    else mvwprintw(Prompt, 1, 0, "Select a card, or type \"g\" for go.");
  609. X    for (;;) {
  610. X        mvwaddch(Prompt, 1, 41, '\n');
  611. X        wrefresh(Prompt);
  612. X        k = wgetch(Prompt);
  613. X        k = (isupper(k) ? tolower(k) : k);
  614. X        if (k == 'g') {
  615. X            if (goodgo(whoseturn)) {
  616. X                whosego = !whoseturn;
  617. X                return;
  618. X            }
  619. X            else beep();
  620. X        }
  621. X        else if (k < 'a' || k > 'd') beep();
  622. X        else if (goodplay(whoseturn, k-'a')) break;
  623. X        else beep();
  624. X    }
  625. X    werase(Prompt);
  626. X    played[whoseturn][k-'a'] = 1;
  627. X    count += rankvalue[RANK(hand[whoseturn][k-'a'])];
  628. X    go[gocount++] = hand[whoseturn][k-'a'];
  629. X    nleft[whoseturn] -= 1;
  630. X    sco = playscore();
  631. X    showhplay(k-'a', sco);
  632. X    if (sco) SCOREUP(whoseturn, sco);
  633. X    handover = !nleft[0] && !nleft[1];
  634. X    if (count==31) resetgo();
  635. X    else if (handover) {
  636. X        mvwprintw(Prompt, 0, 0, "That's a Go\n");
  637. X        SCOREUP(whoseturn, 1);
  638. X    }
  639. X    sleep(1);
  640. X}
  641. END_OF_human.c
  642. if test 2424 -ne `wc -c <human.c`; then
  643.     echo shar: \"human.c\" unpacked with wrong size!
  644. fi
  645. # end of overwriting check
  646. fi
  647. if test -f logaux.c -a "${1}" != "-c" ; then 
  648.   echo shar: Will not over-write existing file \"logaux.c\"
  649. else
  650. echo shar: Extracting \"logaux.c\" \(173 characters\)
  651. sed "s/^X//" >logaux.c <<'END_OF_logaux.c'
  652. X#include "defs.h"
  653. X
  654. Xint
  655. Xcindex(a, b)
  656. XCARD a, b;
  657. X{
  658. X    register t, u;
  659. X    t = RANK(a);
  660. X    u = RANK(b);
  661. X    if (t < u) {
  662. X        t = RANK(b);
  663. X        u = RANK(a);
  664. X    }
  665. X    return u - 1 + (t * (t-1))/2;
  666. X}
  667. END_OF_logaux.c
  668. if test 173 -ne `wc -c <logaux.c`; then
  669.     echo shar: \"logaux.c\" unpacked with wrong size!
  670. fi
  671. # end of overwriting check
  672. fi
  673. if test -f logglobs.c -a "${1}" != "-c" ; then 
  674.   echo shar: Will not over-write existing file \"logglobs.c\"
  675. else
  676. echo shar: Extracting \"logglobs.c\" \(1136 characters\)
  677. sed "s/^X//" >logglobs.c <<'END_OF_logglobs.c'
  678. Xfloat    distable[2][91] = {
  679. X6.290,5.028,6.490,5.092,7.256,6.744,5.776,5.297,5.917,6.699,6.083,6.181,
  680. X6.734,7.222,9.463,4.993,5.068,4.909,5.277,7.528,7.152,5.177,5.145,5.070,
  681. X4.969,7.061,6.503,7.451,4.954,4.970,4.963,4.922,6.283,5.951,8.103,6.808,
  682. X4.725,4.810,4.826,4.745,6.170,6.434,5.402,5.959,6.536,4.504,4.610,4.586,
  683. X4.485,7.476,4.332,4.465,5.043,5.568,6.114,4.786,4.893,4.869,4.767,7.758,
  684. X4.615,4.826,4.678,5.140,5.478,6.666,4.360,4.467,4.443,4.341,7.332,4.189,
  685. X4.400,4.310,4.089,4.564,5.359,5.824,4.211,4.318,4.294,4.192,7.184,4.040,
  686. X4.251,4.162,4.019,3.763,4.650,4.290,5.526,5.580,4.339,5.966,4.585,7.183,
  687. X6.102,5.596,4.545,4.892,5.808,5.562,5.583,6.039,6.501,8.909,3.868,3.876,
  688. X3.839,3.818,6.538,5.846,3.784,3.856,3.678,3.797,5.986,4.795,5.945,3.730,
  689. X3.644,3.879,3.830,5.490,4.448,6.535,5.380,3.453,3.780,3.828,3.780,5.477,
  690. X5.234,3.940,4.531,5.259,3.462,3.602,3.650,3.601,6.725,3.089,3.069,3.742,
  691. X4.130,4.878,3.746,3.886,3.934,3.885,7.009,3.372,3.406,3.348,3.933,4.530,
  692. X5.435,3.534,3.673,3.722,3.672,6.797,3.160,3.194,3.194,3.086,3.336,4.858,
  693. X5.005,3.531,3.671,3.719,3.670,6.794,3.158,3.192,3.191,3.126,2.889,4.031,
  694. X3.469,5.003
  695. X};
  696. END_OF_logglobs.c
  697. if test 1136 -ne `wc -c <logglobs.c`; then
  698.     echo shar: \"logglobs.c\" unpacked with wrong size!
  699. fi
  700. # end of overwriting check
  701. fi
  702. if test -f logglobs.h -a "${1}" != "-c" ; then 
  703.   echo shar: Will not over-write existing file \"logglobs.h\"
  704. else
  705. echo shar: Extracting \"logglobs.h\" \(30 characters\)
  706. sed "s/^X//" >logglobs.h <<'END_OF_logglobs.h'
  707. Xextern    float    distable[2][91];
  708. END_OF_logglobs.h
  709. if test 30 -ne `wc -c <logglobs.h`; then
  710.     echo shar: \"logglobs.h\" unpacked with wrong size!
  711. fi
  712. # end of overwriting check
  713. fi
  714. if test -f nobs.6 -a "${1}" != "-c" ; then 
  715.   echo shar: Will not over-write existing file \"nobs.6\"
  716. else
  717. echo shar: Extracting \"nobs.6\" \(632 characters\)
  718. sed "s/^X//" >nobs.6 <<'END_OF_nobs.6'
  719. X.de QU
  720. X.ie t ``\\$1''\\$2
  721. X.el "\\$1"\\$2
  722. X..
  723. X.TH NOBS 6 "10 March 1988" "" "Local UNIX Programmer's Manual"
  724. X.SH NAME
  725. Xnobs \- cribbage game
  726. X.SH SYNOPSIS
  727. X.B nobs
  728. X[
  729. X.B \-v
  730. X]
  731. X.SH DESCRIPTION
  732. XWith no arguments,
  733. X.I cribbage
  734. Xplays screen-oriented games of cribbage with you.
  735. XYou select cards by typing a letter from
  736. X.QU a
  737. Xto
  738. X.QU f .
  739. XThe program keeps score.
  740. XGame is 121 points.
  741. X.PP
  742. XIf you specify
  743. X.BR \-v ,
  744. X.I cribbage
  745. Xprints the version number and exits.
  746. X.SH WARNING
  747. XThis program has been around a long time, having started out 
  748. Xin FORTRAN on a CDC 6400.
  749. XIt is a dangerous opponent.
  750. X.SH AUTHOR
  751. XG. L. Sicherman  (ihnp4\^!\^odyssey\^!\^gls)
  752. END_OF_nobs.6
  753. if test 632 -ne `wc -c <nobs.6`; then
  754.     echo shar: \"nobs.6\" unpacked with wrong size!
  755. fi
  756. # end of overwriting check
  757. fi
  758. if test -f nobs.c -a "${1}" != "-c" ; then 
  759.   echo shar: Will not over-write existing file \"nobs.c\"
  760. else
  761. echo shar: Extracting \"nobs.c\" \(672 characters\)
  762. sed "s/^X//" >nobs.c <<'END_OF_nobs.c'
  763. X/*
  764. X *    nobs - play cribbage.
  765. X */
  766. X
  767. X#include <stdio.h>
  768. X#include "defs.h"
  769. X#include "globs.h"
  770. X
  771. Xextern    int    programdiscard();
  772. Xextern    int    humandiscard();
  773. X
  774. Xusage()
  775. X{
  776. X    fprintf(stderr,"usage: nobs [-v]\n");
  777. X    exit(-1);
  778. X}
  779. X
  780. Xmain(argc,argv)
  781. Xint argc;
  782. Xchar **argv;
  783. X{
  784. X    while (--argc) {
  785. X        if ('-'==**++argv) switch(*++*argv) {
  786. X        case 'v':
  787. X            printf("Nobs Version %s\n", version);
  788. X            exit(0);
  789. X        default:
  790. X            usage();
  791. X        }
  792. X        else break;
  793. X    }
  794. X    if (argc) usage();
  795. X    initrand();
  796. X    initwins();
  797. X    dealer = randint(2);
  798. X    playertype[0] = PROGRAM;
  799. X    playertype[1] = HUMAN;
  800. X    dscfunc[PROGRAM] = programdiscard;
  801. X    dscfunc[HUMAN] = humandiscard;
  802. X    for (quitflag=0; !quitflag; ) playgame();
  803. X    termwins();
  804. X    exit(0);
  805. X}
  806. END_OF_nobs.c
  807. if test 672 -ne `wc -c <nobs.c`; then
  808.     echo shar: \"nobs.c\" unpacked with wrong size!
  809. fi
  810. # end of overwriting check
  811. fi
  812. if test -f pegs.c -a "${1}" != "-c" ; then 
  813.   echo shar: Will not over-write existing file \"pegs.c\"
  814. else
  815. echo shar: Extracting \"pegs.c\" \(1156 characters\)
  816. sed "s/^X//" >pegs.c <<'END_OF_pegs.c'
  817. X#include "defs.h"
  818. X#include "globs.h"
  819. X#include "window.h"
  820. X
  821. Xint
  822. Xpegcol(n)
  823. Xint n;
  824. X{
  825. X    if (n==0) return 0;
  826. X    else if (n<31) return n+(n+4)/5;
  827. X    else return 74-n-(n+4)/5;
  828. X}
  829. X
  830. Xresetpegs()
  831. X{
  832. X    int i, j;
  833. X    for (i=0; i<2; i++) for (j=0; j<2; j++) {
  834. X        if (peg[i][j] != 0)
  835. X        mvwaddch(Board, 2*i, pegcol(peg[i][j]), ':');
  836. X    }
  837. X    for (i=0; i<2; i++) mvwaddch(Board, 2*i, 0, '|');
  838. X    wrefresh(Board);
  839. X}
  840. X
  841. Xsetpegs(who)
  842. XPLAYER    who;
  843. X{
  844. X/*
  845. X *    The first peg in the array is the forward peg.
  846. X */
  847. X
  848. X/*    Pick up the hindward peg.  */
  849. X    if (peg[who][0] == 0) mvwaddch(Board, 2*who, 0, who? '!': ';');
  850. X    else if (peg[who][1] + peg[who][0] == 61)
  851. X        mvwaddch(Board, 2*who, pegcol(peg[who][1]),
  852. X        (peg[who][1]>30)==who? ';': '!');
  853. X    else mvwaddch(Board, 2*who, pegcol(peg[who][1]), ':');
  854. X/*
  855. X *    Put it down again.
  856. X */
  857. X    peg[who][1] = peg[who][0];
  858. X    if (score[who] > 120) peg[who][0] = 0;
  859. X    else peg[who][0] = 1+(score[who]-1)%60;
  860. X    if (peg[who][0]==0) mvwaddch(Board, 2*who, 0, who? '!': ';');
  861. X    else if (peg[who][0] + peg[who][1] == 61)
  862. X        mvwaddch(Board, 2*who, pegcol(peg[who][0]), '|');
  863. X    else mvwaddch(Board, 2*who, pegcol(peg[who][0]),
  864. X        (peg[who][0]>30)==who? '!': ';');
  865. X    wrefresh(Board);
  866. X    sleep(1);
  867. X}
  868. END_OF_pegs.c
  869. if test 1156 -ne `wc -c <pegs.c`; then
  870.     echo shar: \"pegs.c\" unpacked with wrong size!
  871. fi
  872. # end of overwriting check
  873. fi
  874. if test -f play.c -a "${1}" != "-c" ; then 
  875.   echo shar: Will not over-write existing file \"play.c\"
  876. else
  877. echo shar: Extracting \"play.c\" \(1823 characters\)
  878. sed "s/^X//" >play.c <<'END_OF_play.c'
  879. X#include "defs.h"
  880. X#include "globs.h"
  881. X#include "window.h"
  882. X
  883. Xstatic    taketurn();
  884. X
  885. Xplaygame()
  886. X{
  887. X    char k;
  888. X    score[0]=score[1]=0;
  889. X    resetpegs();
  890. X    for (gameover=0; !gameover; ) playhand();
  891. X    mvwprintw(Prompt, 0, 0, score[0]>120? "I win.\n": "You win.\n");
  892. X    wrefresh(Prompt);
  893. X    sleep(2);
  894. X    mvwprintw(Prompt, 1, 0, "Another game?\n");
  895. X    wmove(Prompt, 1, 41);
  896. X    wrefresh(Prompt);
  897. X    k = wgetch(Prompt);
  898. X    if (k != 'y' && k != 'Y') quitflag = 1;
  899. X}
  900. X
  901. Xplayhand()
  902. X{
  903. X    int i, j;
  904. X    dealer = !dealer;
  905. X    deal();
  906. X    werase(Pscore);
  907. X    werase(Hscore);
  908. X    showhand();
  909. X    ncrib=0;
  910. X    for (i=0; i<2; i++) {
  911. X        (*dscfunc[playertype[i]])(hand[i], i==dealer);
  912. X    }
  913. X    showfour();
  914. X    showcut();
  915. X    if (RANK(cut)==KNAVE) {
  916. X        mvwprintw(Prompt, 1, 0, "Two for His Heels\n");
  917. X        wrefresh(Prompt);
  918. X        sleep(2);
  919. X        SCOREUP(dealer, 2);
  920. X        sleep(1);
  921. X    }
  922. X    whoseturn = dealer;    /* to be reversed */
  923. X    handover = 0;
  924. X    nleft[0]=nleft[1]=4;
  925. X    resetgo();
  926. X    for (i=0; i<2; i++) for (j=0; j<4; j++) played[i][j]=0;
  927. X    while (!gameover && !handover) taketurn();
  928. X    if (gameover) return;
  929. X    gamescore();
  930. X}
  931. X
  932. Xstatic
  933. Xtaketurn()
  934. X{
  935. X    whoseturn = !whoseturn;
  936. X    switch (playertype[whoseturn]) {
  937. X    case HUMAN:
  938. X        humanplay();
  939. X        break;
  940. X    case PROGRAM:
  941. X        programplay();
  942. X        break;
  943. X    }
  944. X}
  945. X
  946. Xint
  947. Xgoodgo(who)
  948. Xint who;
  949. X{
  950. X    int i;
  951. X    for (i=0; i<4; i++) if (goodplay(who, i)) return 0;
  952. X    return 1;
  953. X}
  954. X
  955. Xint
  956. Xgoodplay(who, which)
  957. Xint who, which;
  958. X{
  959. X    return !played[who][which] &&
  960. X    rankvalue[RANK(hand[who][which])] + count <= 31;
  961. X}
  962. X
  963. Xresetgo() {
  964. X    count=gocount=0;
  965. X    whosego = -1;
  966. X    mvwprintw(Prompt, 0, 0, "0.\n");
  967. X    wrefresh(Prompt);
  968. X}
  969. X
  970. X/*
  971. X *    Returns nonzero if wins.
  972. X */
  973. Xscoreup(who, n)
  974. Xint who, n;
  975. X{
  976. X    score[who] += n;
  977. X    setpegs(who);
  978. X    return (score[who] > 120);
  979. X}
  980. X
  981. X/*
  982. X *    assumes a<b.
  983. X */
  984. X
  985. Xmakediscard(hand, a, b)
  986. Xint a, b;
  987. XCARD hand[];
  988. X{
  989. X    crib[ncrib++] = hand[a];
  990. X    crib[ncrib++] = hand[b];
  991. X    hand[b]=hand[5];
  992. X    hand[a]=hand[4];    /* In this order only. */
  993. X}
  994. END_OF_play.c
  995. if test 1823 -ne `wc -c <play.c`; then
  996.     echo shar: \"play.c\" unpacked with wrong size!
  997. fi
  998. # end of overwriting check
  999. fi
  1000. if test -f playscore.c -a "${1}" != "-c" ; then 
  1001.   echo shar: Will not over-write existing file \"playscore.c\"
  1002. else
  1003. echo shar: Extracting \"playscore.c\" \(968 characters\)
  1004. sed "s/^X//" >playscore.c <<'END_OF_playscore.c'
  1005. X#include "defs.h"
  1006. X#include "globs.h"
  1007. X
  1008. Xint
  1009. Xplayscore()
  1010. X{
  1011. X    int hold, low;
  1012. X    hold = 0;
  1013. X    if (count == 15 || count == 31) hold=2;
  1014. X    if (gocount > 1 && RANK(go[gocount-2])==RANK(go[gocount-1])) {
  1015. X        hold += 2;
  1016. X        if (gocount > 2 && RANK(go[gocount-3])==RANK(go[gocount-2])) {
  1017. X            hold += 4;
  1018. X            if (gocount > 3 && RANK(go[gocount-4])==
  1019. X            RANK(go[gocount-3])) hold += 6;
  1020. X        }
  1021. X        return hold;    /* No need to check for runs */
  1022. X    }
  1023. X    if (gocount < 3) return hold;
  1024. X    for (low=0; low<gocount-2; low++)
  1025. X    if (isplrun(low, gocount-low)) return hold+gocount-low;
  1026. X    return hold;
  1027. X}
  1028. X
  1029. Xint
  1030. Xisplrun(start, num)
  1031. Xint start, num;
  1032. X{
  1033. X    int highest, lowest, i;
  1034. X    register mask;
  1035. X    lowest = KING;
  1036. X    highest = ACE;
  1037. X    for (i=start; i<start+num; i++) {
  1038. X        if (RANK(go[i])>highest) highest=RANK(go[i]);
  1039. X        if (RANK(go[i])<lowest) lowest=RANK(go[i]);
  1040. X    }
  1041. X    if (highest != lowest+num-1) return 0;
  1042. X/*
  1043. X *    Use a mask.
  1044. X */
  1045. X    mask = (1<<num)-1;
  1046. X    for (i=start; i<start+num; i++) mask &= ~(1<<(RANK(go[i])-lowest));
  1047. X    return !mask;
  1048. X}
  1049. END_OF_playscore.c
  1050. if test 968 -ne `wc -c <playscore.c`; then
  1051.     echo shar: \"playscore.c\" unpacked with wrong size!
  1052. fi
  1053. # end of overwriting check
  1054. fi
  1055. if test -f progaux.c -a "${1}" != "-c" ; then 
  1056.   echo shar: Will not over-write existing file \"progaux.c\"
  1057. else
  1058. echo shar: Extracting \"progaux.c\" \(1499 characters\)
  1059. sed "s/^X//" >progaux.c <<'END_OF_progaux.c'
  1060. X#include "defs.h"
  1061. X#include "globs.h"
  1062. X#include "logglobs.h"
  1063. X
  1064. Xfloat evaldiscard();
  1065. X
  1066. Xbestdis(hand, mydeal, aw, bw)
  1067. XCARD hand[];
  1068. Xint mydeal;
  1069. Xint *aw, *bw;
  1070. X{
  1071. X    float best, new;
  1072. X    int a, b;
  1073. X    best = -999.0;
  1074. X    for (a=0; a<5; a++) for (b=a+1; b<6; b++) {
  1075. X        new = evaldiscard(hand, mydeal, a, b);
  1076. X        if (new>best) {
  1077. X            best=new;
  1078. X            *aw=a;
  1079. X            *bw=b;
  1080. X        }
  1081. X    }
  1082. X}
  1083. X
  1084. Xfloat
  1085. Xevaldiscard(hand, mydeal, j1, j2)
  1086. XCARD    hand[];
  1087. Xint    mydeal, j1, j2;
  1088. X{
  1089. X    float retval, disval;
  1090. X    CARD holdhand[5], *hp;
  1091. X    int k;
  1092. X    int cutrank;
  1093. X/*
  1094. X *    Evaluate the remaining hand.
  1095. X */
  1096. X    retval = 0.0;
  1097. X    hp=holdhand;
  1098. X    for (k=0; k<6; k++) if (k!=j1 && k!=j2) *hp++ = hand[k];
  1099. X    for (cutrank=ACE; cutrank<=KING; cutrank++) {
  1100. X        *hp = (CABBAGE<<4) | cutrank;
  1101. X        retval += 4 * evalhand(holdhand, 1, -1);
  1102. X    }
  1103. X    retval /= 52;
  1104. X    disval = distable[mydeal][cindex(hand[j1],hand[j2])];
  1105. X    if (!mydeal) disval= -disval;
  1106. X    retval += disval;
  1107. X    return retval;
  1108. X}
  1109. X
  1110. X/*
  1111. X *    This isn't supposed to be a world-class strategy.
  1112. X */
  1113. Xint
  1114. Xevalplay(c)
  1115. XCARD c;
  1116. X{
  1117. X    int v;
  1118. X    v = rankvalue[RANK(c)];
  1119. X    if (count+v == 15 || count+v == 31) return 20;
  1120. X    if (gocount && RANK(go[gocount-1])==RANK(c)) {
  1121. X        if (gocount>1 && RANK(go[gocount-2])==RANK(c)) return 30;
  1122. X        if (gocount>3 || randint(5)) return 15;
  1123. X    }
  1124. X    if (gocount>1 &&
  1125. X    isrun(RANK(go[gocount-1]),RANK(go[gocount-2]), RANK(c))) return 25;
  1126. X    if (gocount && 2==abs(RANK(c)-RANK(go[gocount-1]))) return -10;
  1127. X    if (count+v <= 4) return 10+count+v;
  1128. X    if (count>20) return v;
  1129. X    return 0;
  1130. X}
  1131. X
  1132. Xint
  1133. Xisrun(a,b,c)
  1134. Xint a,b,c;
  1135. X{
  1136. X    return 4==abs(a-b)+abs(a-c)+abs(b-c);
  1137. X}
  1138. END_OF_progaux.c
  1139. if test 1499 -ne `wc -c <progaux.c`; then
  1140.     echo shar: \"progaux.c\" unpacked with wrong size!
  1141. fi
  1142. # end of overwriting check
  1143. fi
  1144. if test -f program.c -a "${1}" != "-c" ; then 
  1145.   echo shar: Will not over-write existing file \"program.c\"
  1146. else
  1147. echo shar: Extracting \"program.c\" \(1784 characters\)
  1148. sed "s/^X//" >program.c <<'END_OF_program.c'
  1149. X/*
  1150. X *    The program's strategy.
  1151. X */
  1152. X
  1153. X#include "defs.h"
  1154. X#include "globs.h"
  1155. X#include "logglobs.h"
  1156. X#include "window.h"
  1157. X
  1158. Xfloat    evaldiscard();
  1159. X
  1160. Xprogramdiscard(ehand, mydeal)
  1161. XCARD ehand[];
  1162. Xint mydeal;
  1163. X{
  1164. X    int aw, bw;
  1165. X    bestdis(ehand, mydeal, &aw, &bw);
  1166. X    makediscard(ehand, aw, bw);
  1167. X    mvwaddch(Programhand, 0, 5*4, '\n');
  1168. X    mvwprintw(Crib, 0, 0, "XXX  XXX\n");
  1169. X    wrefresh(Crib);
  1170. X}
  1171. X
  1172. Xprogramplay()
  1173. X{
  1174. X    int t, u, v;
  1175. X    int bestplay, bestval;
  1176. X    if (goodgo(whoseturn)) {
  1177. X/*
  1178. X *    No legal plays.
  1179. X */
  1180. X        handover = !nleft[0] && !nleft[1];
  1181. X/*
  1182. X *    Case I - it's nobody's go yet.
  1183. X */
  1184. X        if (whosego < 0) {
  1185. X            if (handover) {
  1186. X                SCOREUP(whoseturn, 1);
  1187. X            }
  1188. X            else {
  1189. X/*
  1190. X *    Can't play - it's now the human's go.
  1191. X */
  1192. X                whosego = !whoseturn;
  1193. X/*
  1194. X *    If I have no cards, there's no need to say "go."
  1195. X */
  1196. X                if (nleft[whoseturn]) {
  1197. X                    mvwprintw(Prompt, 0, 11, "Go.\n");
  1198. X                    wrefresh(Prompt);
  1199. X                    sleep(1);
  1200. X                }
  1201. X            }
  1202. X        }
  1203. X        else if (whosego==whoseturn) {
  1204. X/*
  1205. X *    Case II - it's my go.
  1206. X */
  1207. X            SCOREUP(whoseturn, 1);
  1208. X            if (!handover) resetgo();
  1209. X        }
  1210. X        return;
  1211. X    }
  1212. X/*
  1213. X *    I can play.  Pick an appropriate play.
  1214. X */
  1215. X    bestval = -999;
  1216. X    for (t=0; t<4; t++) if (goodplay(whoseturn, t)) {
  1217. X        if ((v=evalplay(hand[whoseturn][t])) > bestval) {
  1218. X            bestval=v;
  1219. X            bestplay=t;
  1220. X        }
  1221. X    }
  1222. X    makeprogplay(bestplay);
  1223. X    return;
  1224. X}
  1225. X
  1226. Xmakeprogplay(t)
  1227. Xint t;
  1228. X{
  1229. X    int sco;
  1230. X    nleft[whoseturn] -= 1;
  1231. X    played[whoseturn][t]=1;
  1232. X    count += rankvalue[RANK(hand[whoseturn][t])];
  1233. X    go[gocount++] = hand[whoseturn][t];
  1234. X    sco = playscore();
  1235. X    showpplay(whoseturn, t, sco);
  1236. X    if (sco) SCOREUP(whoseturn, sco);
  1237. X/*
  1238. X *    Say Go to myself?
  1239. X */
  1240. X    if (!nleft[!whoseturn]) whosego=whoseturn;
  1241. X    handover = !nleft[0] && !nleft[1];
  1242. X    if (count==31) resetgo();
  1243. X    else if (handover) {
  1244. X        mvwprintw(Prompt, 1, 0, "That's a Go\n");
  1245. X        wrefresh(Prompt);
  1246. X        sleep(1);
  1247. X        SCOREUP(whoseturn, 1);
  1248. X    }
  1249. X}
  1250. END_OF_program.c
  1251. if test 1784 -ne `wc -c <program.c`; then
  1252.     echo shar: \"program.c\" unpacked with wrong size!
  1253. fi
  1254. # end of overwriting check
  1255. fi
  1256. if test -f show.c -a "${1}" != "-c" ; then 
  1257.   echo shar: Will not over-write existing file \"show.c\"
  1258. else
  1259. echo shar: Extracting \"show.c\" \(2076 characters\)
  1260. sed "s/^X//" >show.c <<'END_OF_show.c'
  1261. X#include "defs.h"
  1262. X#include "globs.h"
  1263. X#include "window.h"
  1264. X
  1265. Xchar *
  1266. Xcardname(c)
  1267. XCARD c;
  1268. X{
  1269. X    static char hold[4];
  1270. X    sprintf(hold, "%2s%s", rankrdr[RANK(c)], suitrdr[SUIT(c)]);
  1271. X    return hold;
  1272. X}
  1273. X
  1274. Xshowhand()
  1275. X/*
  1276. X *    If a player is human, it's always player 1.
  1277. X */
  1278. X{
  1279. X    int i;
  1280. X    for (i=0; i<6; i++) mvwprintw(Programhand, 0, 5*i, "XXX");
  1281. X    for (i=0; i<6; i++) mvwprintw(Humanhand, 2, 5*i, cardname(hand[1][i]));
  1282. X    mvwprintw(Programhand, 2, 0, "\n");
  1283. X    mvwprintw(Humanhand, 0, 0, "\n");
  1284. X    werase(Cut);
  1285. X    werase(Crib);
  1286. X    werase(Pscore);
  1287. X    werase(Hscore);
  1288. X    werase(Select);
  1289. X    wrefresh(Cut);
  1290. X    wrefresh(Crib);
  1291. X    wrefresh(Pscore);
  1292. X    wrefresh(Hscore);
  1293. X    wrefresh(Select);
  1294. X    wrefresh(Programhand);
  1295. X    wrefresh(Humanhand);
  1296. X}
  1297. X
  1298. Xshowfour()
  1299. X{
  1300. X    int i;
  1301. X    werase(Humanhand);
  1302. X    for (i=0; i<4; i++) mvwprintw(Humanhand, 2, 5*i, cardname(hand[1][i]));
  1303. X    waddch(Humanhand,'\n');
  1304. X    for (i=2; i<4; i++) mvwprintw(Crib, 0, 5*i, "XXX  ");
  1305. X    for (i=0; i<4; i++) mvwaddch(Select, 0, 5*i+2, 'a'+i);
  1306. X
  1307. X    wrefresh(Humanhand);
  1308. X    wrefresh(Crib);
  1309. X    wrefresh(Select);
  1310. X}
  1311. X
  1312. Xshowpplay(who, i, scored)
  1313. Xint who, i, scored;
  1314. X{
  1315. X    mvwprintw(Programhand, 0, 5*i, "   ");
  1316. X    mvwprintw(Programhand, 2, 5*(3-nleft[who]), cardname(hand[who][i]));
  1317. X    if (scored) mvwprintw(Prompt, 0, 0, "%d for %d.\n", count, scored);
  1318. X    else mvwprintw(Prompt, 0, 0, "%d.\n", count);
  1319. X    wrefresh(Programhand);
  1320. X    wrefresh(Prompt);
  1321. X    sleep(2);
  1322. X}
  1323. X
  1324. Xshowhplay(i, scored)
  1325. Xint i, scored;
  1326. X{
  1327. X    mvwprintw(Humanhand, 2, 5*i, "   ");
  1328. X    mvwprintw(Humanhand, 0, 5*(3-nleft[1]), cardname(hand[1][i]));
  1329. X    if (scored) mvwprintw(Prompt, 0, 0, "%d for %d.\n", count, scored);
  1330. X    else mvwprintw(Prompt, 0, 0, "%d.\n", count);
  1331. X    wrefresh(Humanhand);
  1332. X    wrefresh(Prompt);
  1333. X}
  1334. X
  1335. Xshowcut()
  1336. X{
  1337. X    mvwprintw(Prompt, 0, 0, playertype[dealer]==HUMAN? "I cut:\n":
  1338. X        "You cut:\n");
  1339. X    mvwaddch(Prompt, 1, 0, '\n');
  1340. X    wrefresh(Prompt);
  1341. X    sleep(1);
  1342. X    mvwprintw(Prompt, 1, 0, "the %s of %s\n",
  1343. X        rankname[RANK(cut)], suitname[SUIT(cut)]);
  1344. X    mvwprintw(Cut, 0, 0, cardname(cut));
  1345. X    wrefresh(Prompt);
  1346. X    wrefresh(Cut);
  1347. X    sleep(1);
  1348. X}
  1349. X
  1350. Xexposecrib()
  1351. X{
  1352. X    int i;
  1353. X    for (i=0; i<6; i++) mvwprintw(Crib, 0, 5*i, cardname(crib[i]));
  1354. X    wrefresh(Crib);
  1355. X    sleep(1);
  1356. X}
  1357. END_OF_show.c
  1358. if test 2076 -ne `wc -c <show.c`; then
  1359.     echo shar: \"show.c\" unpacked with wrong size!
  1360. fi
  1361. # end of overwriting check
  1362. fi
  1363. if test -f shuf.c -a "${1}" != "-c" ; then 
  1364.   echo shar: Will not over-write existing file \"shuf.c\"
  1365. else
  1366. echo shar: Extracting \"shuf.c\" \(811 characters\)
  1367. sed "s/^X//" >shuf.c <<'END_OF_shuf.c'
  1368. X/*
  1369. X *    shuf - shuffle the pack.
  1370. X */
  1371. X
  1372. X#include "defs.h"
  1373. X#include "globs.h"
  1374. X
  1375. X#ifdef    BSD
  1376. Xint    srand();
  1377. Xint    rand();
  1378. X#else
  1379. Xvoid    srand48();
  1380. Xdouble    drand48();
  1381. X#endif
  1382. X
  1383. Xstatic    makepack();
  1384. X
  1385. Xvoid
  1386. Xshuf()
  1387. X{
  1388. X    int j, k;
  1389. X    CARD dummy;
  1390. X    if (!packmade) makepack();
  1391. X    for (j=51; j>=39; j--) {
  1392. X        k = randint(j+1);
  1393. X        dummy = pack[k];
  1394. X        pack[k] = pack[j];
  1395. X        pack[j] = dummy;
  1396. X    }
  1397. X}
  1398. X
  1399. Xstatic
  1400. Xmakepack()
  1401. X{
  1402. X    int suit, rank;
  1403. X    CARD *packp;
  1404. X    packp = pack;
  1405. X    for (suit=CLUB; suit<=SPADE; suit++)
  1406. X    for (rank=ACE; rank<=KING; rank++)
  1407. X        *packp++ = MAKECARD(rank,suit);
  1408. X}
  1409. X
  1410. Xinitrand()
  1411. X{
  1412. X    long time();
  1413. X#ifdef    BSD
  1414. X    srand(time((long *)0));
  1415. X    rand();
  1416. X#else
  1417. X    srand48(time((long *)0));
  1418. X    drand48();
  1419. X#endif
  1420. X}
  1421. X
  1422. X/*
  1423. X *    Returns a random integer from 0 to n-1.
  1424. X */
  1425. Xint
  1426. Xrandint(n)
  1427. Xint n;
  1428. X{
  1429. X#ifdef    BSD
  1430. X    return (rand()/3) % n;
  1431. X#else
  1432. X    return (int)(drand48()*n);
  1433. X#endif
  1434. X}
  1435. END_OF_shuf.c
  1436. if test 811 -ne `wc -c <shuf.c`; then
  1437.     echo shar: \"shuf.c\" unpacked with wrong size!
  1438. fi
  1439. # end of overwriting check
  1440. fi
  1441. if test -f version.c -a "${1}" != "-c" ; then 
  1442.   echo shar: Will not over-write existing file \"version.c\"
  1443. else
  1444. echo shar: Extracting \"version.c\" \(24 characters\)
  1445. sed "s/^X//" >version.c <<'END_OF_version.c'
  1446. Xchar    version[] = "1.0";
  1447. END_OF_version.c
  1448. if test 24 -ne `wc -c <version.c`; then
  1449.     echo shar: \"version.c\" unpacked with wrong size!
  1450. fi
  1451. # end of overwriting check
  1452. fi
  1453. if test -f wglobs.c -a "${1}" != "-c" ; then 
  1454.   echo shar: Will not over-write existing file \"wglobs.c\"
  1455. else
  1456. echo shar: Extracting \"wglobs.c\" \(167 characters\)
  1457. sed "s/^X//" >wglobs.c <<'END_OF_wglobs.c'
  1458. X#include <curses.h>
  1459. X
  1460. XWINDOW    *Crib;
  1461. XWINDOW    *Select;
  1462. XWINDOW    *Board;
  1463. XWINDOW    *Cut;
  1464. XWINDOW    *Hscore;
  1465. XWINDOW    *Humanhand;
  1466. XWINDOW    *Programhand;
  1467. XWINDOW    *Prompt;
  1468. XWINDOW    *Pscore;
  1469. END_OF_wglobs.c
  1470. if test 167 -ne `wc -c <wglobs.c`; then
  1471.     echo shar: \"wglobs.c\" unpacked with wrong size!
  1472. fi
  1473. # end of overwriting check
  1474. fi
  1475. if test -f window.c -a "${1}" != "-c" ; then 
  1476.   echo shar: Will not over-write existing file \"window.c\"
  1477. else
  1478. echo shar: Extracting \"window.c\" \(690 characters\)
  1479. sed "s/^X//" >window.c <<'END_OF_window.c'
  1480. X#include "defs.h"
  1481. X#include "globs.h"
  1482. X#include "window.h"
  1483. X
  1484. Xinitwins()
  1485. X{
  1486. X    initscr();
  1487. X    Humanhand = subwin(stdscr, 3, 29, 16, 30);
  1488. X    Programhand = subwin(stdscr, 3, 28, 5, 30);
  1489. X    Prompt = subwin(stdscr, 2, 72, 22, 5);
  1490. X    Select = subwin(stdscr, 1, 28, 19, 30);
  1491. X    Crib = subwin(stdscr, 1, 20, 12, 1);
  1492. X    Cut = subwin(stdscr, 1, 3, 12, 66);
  1493. X    Hscore = subwin(stdscr, 5, 27, 15, 0);
  1494. X    Pscore = subwin(stdscr, 5, 27, 2, 0);
  1495. X    scrollok(Hscore, TRUE);
  1496. X    scrollok(Pscore, TRUE);
  1497. X    Board = subwin(stdscr, 3, 37, 11, 28);
  1498. X    initboard();
  1499. X}
  1500. X
  1501. Xinitboard()
  1502. X{
  1503. X    int i;
  1504. X    for (i=0; i<37; i++) if (1 != (i%6)) {
  1505. X        mvwaddch(Board, 0, i, ':');
  1506. X        mvwaddch(Board, 2, i, ':');
  1507. X    }
  1508. X}
  1509. X
  1510. Xtermwins()
  1511. X{
  1512. X    clear();
  1513. X    refresh();
  1514. X    endwin();
  1515. X}
  1516. END_OF_window.c
  1517. if test 690 -ne `wc -c <window.c`; then
  1518.     echo shar: \"window.c\" unpacked with wrong size!
  1519. fi
  1520. # end of overwriting check
  1521. fi
  1522. if test -f window.h -a "${1}" != "-c" ; then 
  1523.   echo shar: Will not over-write existing file \"window.h\"
  1524. else
  1525. echo shar: Extracting \"window.h\" \(229 characters\)
  1526. sed "s/^X//" >window.h <<'END_OF_window.h'
  1527. X#include <curses.h>
  1528. Xextern    WINDOW    *Crib;
  1529. Xextern    WINDOW    *Board;
  1530. Xextern    WINDOW    *Select;
  1531. Xextern    WINDOW    *Cut;
  1532. Xextern    WINDOW    *Hscore;
  1533. Xextern    WINDOW    *Humanhand;
  1534. Xextern    WINDOW    *Programhand;
  1535. Xextern    WINDOW    *Prompt;
  1536. Xextern    WINDOW    *Pscore;
  1537. END_OF_window.h
  1538. if test 229 -ne `wc -c <window.h`; then
  1539.     echo shar: \"window.h\" unpacked with wrong size!
  1540. fi
  1541. # end of overwriting check
  1542. fi
  1543. echo shar: End of archive 1 \(of 1\).
  1544. cp /dev/null ark1isdone
  1545. MISSING=""
  1546. for I in 1 ; do
  1547.     if test ! -f ark${I}isdone ; then
  1548.     MISSING="${MISSING} ${I}"
  1549.     fi
  1550. done
  1551. if test "${MISSING}" = "" ; then
  1552.     echo You have unpacked all 1 archives.
  1553.     rm -f ark[1-9]isdone
  1554. else
  1555.     echo You still need to unpack the following archives:
  1556.     echo "        " ${MISSING}
  1557. fi
  1558. ##  End of shell archive.
  1559. exit 0
  1560.